<%@page import="classes.Valuta"%>
<%@include file="template/configuration.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<% pageContext.setAttribute("newLineChar", "\n"); %>
<c:if test="${servlet == null}">
    <% response.sendRedirect("Index"); %>
</c:if>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Homepage</title>
        ${stylesheet}
        ${jquery}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>${uq_welcome} <c:choose><c:when test="${sessionScope.userdetails!=null}">${sessionScope.userdetails.firstname} ${sessionScope.userdetails.insertion} ${sessionScope.userdetails.lastname}</c:when><c:otherwise>visitor</c:otherwise></c:choose></h1>
                <div class="full-block">
                    <div class="slideshow <c:choose><c:when test="${sessionScope.userdetails!=null}">loggedin</c:when></c:choose>">
                        <%@include file="template/slider.jsp" %>
                    </div>
                </div>
                <p>
                    <c:forEach items="${page}" var="p">
                        ${fn:replace(p.content, newLineChar, "<br />")}
                    </c:forEach>
                </p>
                <c:choose> <c:when  test="${sessionScope.userdetails!=null}">
                <div class="blocks">
                    <div class="third-block">
                        <h2>${uq_next_lessons}</h2>
                        <c:forEach items="${next}" var="next">
                            <div class="information">
                                <a href="${url}LectureController?courseid=${next[0].id}&id=${next[1].id}">
                                    <div class="title">
                                        ${next[0].name}
                                    </div>
                                    <div class="date">
                                        <fmt:formatDate pattern="yyyy-MM-dd" value="${next[2].date.time}" />
                                    </div>
                                    <div class="clear"></div>
                                    <span>
                                        <c:choose>
                                            <c:when test="${fn:length(next[1].name) > 15}">
                                                '<c:out value="${fn:substring(next[1].name, 0, 15)}"/>...'
                                            </c:when>
                                            <c:otherwise>
                                                '${next[1].name}'
                                            </c:otherwise>
                                        </c:choose>
                                        starts at <fmt:formatDate pattern="HH:mm" value="${next[2].date.time}" />
                                    </span>
                                </a>
                            </div>
                        </c:forEach>
                        <div class="button"><a href="">${uq_see_more}</a></div>
                    </div>
                    <div class="third-block">
                        <h2>${uq_last_updates}</h2>
                        <c:if test="${sessionScope.userrole != 'Student'}">Updates are not available.</c:if>
                        <c:forEach items="${updates}" var="update">
                            <div class="information">
                                <a href="${url}LectureController?courseid=${update[0].id}&id=${update[1].id}">
                                    <div class="title">
                                        ${update[0].name}
                                    </div>
                                    <div class="date">
                                        ${update[1].date}
                                    </div>
                                    <div class="clear"></div>
                                    <span>
                                        ${update[1].name} added
                                    </span>
                                </a>
                            </div>
                        </c:forEach>
                        <div class="button"><a href="">${uq_see_more}</a></div>
                    </div>
                    <div class="third-block">
                        <h2>${uq_newest_courses}</h2>
                        <c:forEach items="${newest}" var="course">
                            <div class="information">
                                <a href="${url}Course?courseid=${course.id}">
                                    <div class="title">
                                        ${course.name}
                                    </div>
                                    <div class="date">
                                        ${course.date}
                                    </div>
                                    <div class="clear"></div>
                                    <span>
                                        <c:set var="price" value="${course.price}" />
                                        <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                        <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                    </span>
                                </a>
                            </div>
                        </c:forEach>
                        <div class="button"><a href="">${uq_see_more}</a></div>
                    </div>
                </div>
                 </c:when>
            <c:otherwise>
                <div class="blocks">
                    <div class="third-block">
                        <h2>${uq_free_lessons}</h2>
                        <c:forEach items="${free}" var="free">
                            <div class="information">
                                <a href="${url}Course?courseid=${free[0].id}">
                                    <div class="title">
                                        ${free[0].name}
                                    </div>
                                    <div class="clear"></div>
                                    <span>
                                        Free lesson
                                    </span>
                                </a>
                            </div>
                        </c:forEach>
                        <div class="button"><a href="">${uq_see_more}</a></div>
                    </div>
                    <div class="signup">
                        <a href="jsp/register.jsp"></a>
                    </div>
                    <div class="third-block">
                        <h2>${uq_newest_courses}</h2>
                        <c:forEach items="${newest}" var="course">
                            <div class="information">
                                <a href="${url}Course?courseid=${course.id}">
                                    <div class="title">
                                        ${course.name}
                                    </div>
                                    <div class="date">
                                        ${course.date}
                                    </div>
                                    <div class="clear"></div>
                                    <span>
                                        <c:set var="price" value="${course.price}" />
                                        <%=Valuta.getSignFromCurrency(pageContext.getAttribute("currency").toString())%> 
                                        <%=Valuta.calculateToCurrency(pageContext.getAttribute("currency").toString(), (Double) Double.parseDouble(pageContext.getAttribute("price").toString()))%>
                                    </span>
                                </a>
                            </div>
                        </c:forEach>
                        <div class="button"><a href="">${uq_see_more}</a></div>
                    </div>
                </div></c:otherwise></c:choose>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
